package com.epalmpay.service.datareport.impl;

import com.epalmpay.dto.datareport.GroupWelcomeDataOutDTO;
import com.epalmpay.entity.DevicePosRepair;
import com.epalmpay.entity.StatisGroup;
import com.epalmpay.mapper.DevicePosRepairMapper;
import com.epalmpay.mapper.StatisGroupMapper;
import com.epalmpay.service.datareport.IGroupStatisticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by lifayi on 2017/6/13.
 */
@Service
public class GroupStatisticServiceImpl implements IGroupStatisticService {

    @Autowired
    private StatisGroupMapper statisGroupMapper;
    @Autowired
    private DevicePosRepairMapper devicePosRepairMapper;

    @Override
    public GroupWelcomeDataOutDTO index(Long groupId) {
        GroupWelcomeDataOutDTO groupWelcomeDataOutDTO = new GroupWelcomeDataOutDTO();

        StatisGroup statisGroup = statisGroupMapper.selectByGroupId(groupId);
        if(statisGroup != null) {
            groupWelcomeDataOutDTO.setAllAgentNum(statisGroup.getAgentNum());
            groupWelcomeDataOutDTO.setAllMemberNum(statisGroup.getMemberNum());
            groupWelcomeDataOutDTO.setAllShopNum(statisGroup.getShopNum());

            groupWelcomeDataOutDTO.setMonthNewAgent(statisGroup.getThisAgentNum());
            groupWelcomeDataOutDTO.setMonthNewShop(statisGroup.getThisShopNum());

            groupWelcomeDataOutDTO.setTerminalNum(statisGroup.getPosNum());

            groupWelcomeDataOutDTO.setMonthShopTradeAmount(statisGroup.getThisTradeAmount());
            groupWelcomeDataOutDTO.setMonthShopProfitEstimate(statisGroup.getThisIncomeAmount());
        }

        Integer repairPosNum = devicePosRepairMapper.countRepairPos(groupId);
        groupWelcomeDataOutDTO.setRepairTerminalNum(repairPosNum);

        return groupWelcomeDataOutDTO;
    }
}
